<template>
  <div
    :style="`background-image:url('https://meiriyiwen.com/images/new_feed/bg_${myRandom}.jpg')`"
    class="my-message"
  >
    <div class="header">
      <div class="logo">
        <span @click="getBook">每日一文</span>
        <span @click="getBook">文章</span>
      </div>
      <div class="return">
        <router-link to="/home/moment"
          ><img src="../assets/images/return.png" alt=""
        /></router-link>
      </div>
    </div>
    <div class="message">
      <div class="msg">
        <h3>{{ book.bookname }}</h3>
        <span>{{ book.author }}</span>
        <p>{{ book.content1 }}</p>
        <p>{{ book.content2 }}</p>
        <p>{{ book.content3 }}</p>
        <p>{{ book.content4 }}</p>
        <p>{{ book.content5 }}</p>
        <p>{{ book.content6 }}</p>
        <p>{{ book.content7 }}</p>

        <div class="randomBtn">
          <button @click="getBook">随机文章</button>
        </div>
      </div>
    </div>
    <div class="code-box">
      <div class="img-box">
        <img src="../assets/images/footer-code.jpg" alt="" />
      </div>
    </div>
    <div class="footer-box">
      <div class="footer">
        <ul>
          <li><a href="javascript:;">app下载</a></li>
          <li><a href="javascript:;">手机版</a></li>
          <li><a href="javascript:;">关于</a></li>
          <li><a href="javascript:;">官方微博</a></li>
          <li><a href="javascript:;">吾志</a></li>
        </ul>
        <div class="right">
          <span>沪ICP备13000040号-6 </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "message",
  data() {
    return {
      book: {},
      myRandom: "",
    };
  },
  methods: {
    Random() {
      return Math.floor(Math.random() * (99 - 1) + 1);
    },
    getBook() {
      let random = Math.floor(Math.random() * 20);
      axios.get("/book.json").then((res) => {
        // console.log(res.data);
        this.book = res.data[random];
        // console.log(this.book);
        this.myRandom = this.Random();
      });
    },
  },
  mounted() {
     this.myRandom = this.Random();
    let random = Math.floor(Math.random() * 20);
    axios.get("/book.json").then((res) => {
      // console.log(res.data);
      this.book = res.data[random];
      console.log(this.book);
    });
  },
};
</script>

<style lang="less" scoped>
.my-message {
  width: 100%;
  background-image: url("https://meiriyiwen.com/images/new_feed/bg_36.jpg");
  background-attachment: fixed;
  background-size: cover;
  .header {
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(255, 255, 255, 1);
    user-select: none;
    .logo {
      padding-left: 20px;
      span {
        cursor: pointer;
        display: inline-block;
        &:nth-of-type(1) {
          font-size: 32px;
          margin-right: 40px;
          color: #ccc;
          font-weight: bold;
        }
        &:nth-of-type(2) {
          position: absolute;
          left: 200px;
          top: 18px;
          color: #0cb1e4;
        }
      }
    }
    .return {
      padding-right: 20px;
      img {
        width: 40px;
        transform: rotate(90deg);
        cursor: pointer;
      }
    }
  }
  .message {
    width: 780px;
    margin: 0 auto;
    background-color: #fff;
    box-shadow: 0 0 2px rgb(0 0 0 / 20%), 0 1px 1px rgb(0 0 0 / 20%),
      0 3px 0 #ffffff, 0 4px 0 rgb(0 0 0 / 20%), 0 6px 0 #ffffff,
      0 7px 0 rgb(0 0 0 / 20%);
    border-radius: 5px;
    padding: 5px;
    margin-top: 45px;
    margin-bottom: 20px;
    .msg {
      width: 100%;
      border: 1px dashed #ccc;
      padding: 40px 60px;
      box-sizing: border-box;
      h3 {
        font-size: 22px;
        text-align: center;
        margin: 40px 0;
      }
      span {
        display: block;
        width: 100%;
        text-align: center;
        color: #797979;
        margin-bottom: 40px;
      }
      p {
        line-height: 28px;
        font-size: 17px;
        margin-bottom: 35px;
        font-family: "微软雅黑";
        color: #707070;
      }
    }
  }
  .randomBtn {
    text-align: center;
    margin-top: 140px;
    user-select: none;
    button {
      font-size: 15px;
      background-color: #ffb94b;
      border: 1px solid #f59c0c;
      border-radius: 3px;
      padding: 4px 10px;
      text-shadow: 1px 1px 1px #ccc;
      color: #593000;
      cursor: pointer;
    }
  }
  .code-box {
    width: 780px;
    padding: 5px;
    background-color: #fff;
    margin: 0 auto;
    border-radius: 4px;
    user-select: none;
    .img-box {
      width: 100%;
      border: 1px dashed #ccc;
      padding-top: 2px;
      box-sizing: border-box;
      img {
        width: 100%;
      }
    }
  }
  .footer-box {
    background-color: #fff;
    height: 70px;
    margin-top: 65px;
    a,
    span {
      color: #808080;
      font-size: 14px;
    }
    .footer {
      width: 780px;
      margin: 0 auto;
      position: relative;
      ul {
        display: flex;
        height: 70px;
        align-items: center;
        li {
          margin-right: 10px;
          &:nth-of-type(1) {
            border: 1px solid deepskyblue;
            padding: 6px 10px;
          }
        }
      }
      .right {
        position: absolute;
        right: 0;
        bottom: 25px;
      }
    }
  }
}
</style>